home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / filesyst / ncpfs / mars_dos.000 / mars_dos / netpc / netcall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-20  |  9.3 KB  |  419 lines

  1. /* netcall.c: 05-Apr-96 */
  2.  
  3. /****************************************************************
  4.  * (C)opyright (C) 1993,1996  Martin Stover, Marburg, Germany   *
  5.  ****************************************************************/
  6.  
  7. #include "net.h"
  8.  
  9. int neterrno=0;
  10.  
  11. int ipx_init(void)
  12. {
  13. static int ipx_is_init=0;
  14. static int ipx_is_ok  =0;
  15.   if (!ipx_is_init) {
  16.     ipx_is_init++;
  17.     ipx_is_ok = IPXinit();
  18.   }
  19.   return(ipx_is_ok);
  20. }
  21.  
  22. static void *get_shell_ptr(uint16 func)
  23. {
  24.   if (ipx_init()) {
  25.     void *p = NULL;
  26.     REGS    regs;
  27.     SREGS   sregs;
  28.     regs.x.ax = func;
  29.     if (!(intdosx(®s, ®s, &sregs) & 0xff))
  30.       p = MK_FP(sregs.es, regs.x.si);
  31.     return(p);
  32.   } else return(NULL);
  33. }
  34.  
  35. int detach(int servernmbr)
  36. {
  37.   REGS regsin, regsout;
  38.   regsin.x.ax = 0xf101;
  39.   regsin.x.dx = servernmbr;
  40.   return(intdos(®sin, ®sout) & 0xff);
  41. }
  42.  
  43. int logout(void)
  44. {
  45.   REGS regsin, regsout;
  46.   regsin.x.ax = 0xd700;
  47.   return(intdos(®sin, ®sout) & 0xff);
  48. }
  49.  
  50. int redir_device_drive(int devicetyp, uint8 *devname, uint8 *remotename)
  51. /* if devicetyp == -1, the redir is canceled */
  52. /* devicetyp 3 = printer    */
  53. /* devicetyp 4 = disk drive */
  54. {
  55.    REGS    regs;
  56.    SREGS   sregs;
  57.    int     result;
  58.    uint8   buff1[16];
  59.    uint8   buff2[128];
  60.    uint8   *ldevname    = buff1;
  61.    uint8   *lremotename = buff2;
  62.    strncpy(ldevname,    devname,    16);
  63.    regs.x.ax = (devicetyp == -1) ? 0x5f04 : 0x5f03;
  64.    regs.h.bl = (uint8)devicetyp;
  65.    regs.x.cx = 0x574e; /* user sign 'NW' */
  66.    sregs.ds  = FP_SEG(ldevname);
  67.    regs.x.si = FP_OFF(ldevname);
  68.    if (devicetyp > -1) {
  69.      strncpy(lremotename, remotename, 128);
  70.      sregs.es  = FP_SEG(lremotename);
  71.      regs.x.di = FP_OFF(lremotename);
  72.    }
  73.    result = intdosx(®s, ®s, &sregs);
  74.    return(regs.x.cflag ? -result : 0);
  75. }
  76.  
  77. int list_redir(int index, int *devicetyp, uint8 *devname, uint8 *remotename)
  78. {
  79.    REGS    regs;
  80.    SREGS   sregs;
  81.    int     result;
  82.    uint8   buff1[16];
  83.    uint8   buff2[128];
  84.    uint8   *ldevname    = buff1;
  85.    uint8   *lremotename = buff2;
  86.    memset(ldevname,    0, sizeof(buff1));
  87.    memset(lremotename, 0, sizeof(buff2));
  88.    regs.x.ax = 0x5f02;
  89.    regs.x.bx = index;
  90.    regs.x.cx = 0x574e; /* user sign 'NW' */
  91.    sregs.ds  = FP_SEG(ldevname);
  92.    regs.x.si = FP_OFF(ldevname);
  93.    sregs.es  = FP_SEG(lremotename);
  94.    regs.x.di = FP_OFF(lremotename);
  95.    result = intdosx(®s, ®s, &sregs);
  96.    if (!regs.x.cflag) {
  97.      if (devname)    strcpy(devname,    ldevname);
  98.      if (remotename) strcpy(remotename, lremotename);
  99.      if (devicetyp)  *devicetyp = (int)regs.h.bl;
  100.      return((int)regs.h.bh);
  101.    } else return(-result);
  102. }
  103.  
  104. int get_drive_info(uint8 drivenumber, uint8 *connid,
  105.                    uint8 *dhandle,    uint8 *statusflags)
  106.  
  107. /* drivenumber 0 .. 31 */
  108. {
  109.   uint8 *drive_handle_table = get_shell_ptr(0xef00);
  110.   uint8 *drive_flag_table   = get_shell_ptr(0xef01);
  111.   uint8 *drive_conn_table   = get_shell_ptr(0xef02);
  112.  
  113.   if (  !drive_handle_table
  114.      || !drive_flag_table
  115.      || !drive_conn_table
  116.      || drivenumber > 31) {
  117.      char path[100];
  118.      if (drivenumber < 2 || !getcurdir(drivenumber+1, path)) {
  119.        *dhandle     = 0;
  120.        *connid      = 0;
  121.        *statusflags = 0x80;
  122.        return(0);
  123.      }
  124.      return(-1);
  125.   }
  126.   *dhandle     = *(drive_handle_table+ drivenumber);
  127.   *connid      = *(drive_conn_table  + drivenumber);
  128.   *statusflags = *(drive_flag_table  + drivenumber);
  129.   return(0);
  130. }
  131.  
  132. typedef struct {
  133.   char fsname[8][48];
  134. } SERVER_NAME_TABLE;
  135.  
  136. int get_fs_name(int connid, char *name)
  137. /* Connection 1 .. 8 */
  138. {
  139.   SERVER_NAME_TABLE *sf_t = get_shell_ptr(0xef04);
  140.   if (sf_t && connid > 0 && connid-- < 8){
  141.     strmaxcpy(name, sf_t->fsname[connid], 48);
  142.     return(0);
  143.   }
  144.   name[0] = '\0';
  145.   return(-11);
  146. }
  147.  
  148. static char *path_env_name="PATH";
  149.  
  150. int get_search_drive_vektor(SEARCH_VECTOR_ENTRY *vec)
  151. /* maximal 16 Entries */
  152. {
  153.   char *path=getglobenv(path_env_name);
  154.   SEARCH_VECTOR_ENTRY *v = vec;
  155.   int anz=0;
  156.   v->drivenummer = 0xff;
  157.   if (path){
  158.     while (*path && anz++ < 16){
  159.       char *p1 = path;
  160.       int  len = 0;
  161.       while (*path && *path++ !=';') len++;
  162.       if (*(p1+1) == ':' && *p1 >= 'A' &&  *p1 <= 'Z') {
  163.         v->drivenummer =  *p1 - 'A';
  164.         get_drive_info(v->drivenummer, &(v->connid),
  165.            &(v->dhandle), &(v->flags));
  166.         strmaxcpy(v->dospath, p1+2, min(len-2, sizeof(v->dospath)-1));
  167.       } else {
  168.         v->flags       = 0;
  169.         v->drivenummer = 0xfe;  /* ergibt ? */
  170.         strmaxcpy(v->dospath, p1, min(len, sizeof(v->dospath)-1));
  171.       }
  172.       (++v)->drivenummer =  0xff;
  173.       if (*path == ';') path++;
  174.     }
  175.   }
  176.   return(0);
  177. }
  178.  
  179. int set_search_drive_vektor(SEARCH_VECTOR_ENTRY *vec)
  180. {
  181.   char path[256];
  182.   char *p=path;
  183.   SEARCH_VECTOR_ENTRY *v;
  184.   int  plen=strlen(path_env_name);
  185.   int  maxcount=16;
  186.   strcpy(path, path_env_name);
  187.   path[plen]   = '=';
  188.   path[++plen] = '\0';
  189.  
  190.   while (maxcount-- && (NULL != (v = vec++)) && v->drivenummer != 0xff){
  191.     if (v->drivenummer < 26 || *(v->dospath)) {
  192.       if (p > path) *p++=';';
  193.       else p+=plen;
  194.       if (v->drivenummer < 26) {
  195.         *p++ = (char) v->drivenummer + 'A';
  196.         *p++ = ':';
  197.         if (*v->dospath) {
  198.           strcpy(p,  v->dospath);
  199.           p+= strlen(v->dospath);
  200.         } else {
  201.           *p++='.';
  202.           *p  ='\0';
  203.         }
  204.       } else {
  205.         strcpy(p,  v->dospath);
  206.         p+= strlen(v->dospath);
  207.       }
  208.     }
  209.   }
  210.   return(putglobenv(path));
  211. }
  212.  
  213. int alloc_dir_handle(int func,
  214.                      int dhandle,
  215.                      char *path,
  216.                      int driveletter,
  217.                      uint8 *effrights)
  218. {
  219.   int pathlen = (path == NULL) ? 0 : strlen(path);
  220.   struct {
  221.     uint16  len;
  222.     uint8   func;
  223.     uint8   dhandle;
  224.     uint8   drive;
  225.     uint8   pathlen;
  226.     uint8   path[256];
  227.   } req;
  228.   struct {
  229.    uint16  len;
  230.    uint8   newhandle;
  231.    uint8   effrights;
  232.   } repl;
  233.   req.func    = (uint8)func;
  234.   req.dhandle = (uint8)dhandle;
  235.   req.drive   = (uint8)driveletter;
  236.   req.pathlen = (uint8)pathlen;
  237.   xmemmove(req.path, path, pathlen);
  238.   req.len     = 4 + pathlen;
  239.   repl.len    = 2;
  240. /*
  241.   printf("alloc_dir_handle, path=%s, len=%d, disk=%c\n", path, pathlen, driveletter);
  242. */
  243.   neterrno    =  Net_Call(0xE200, &req, &repl);
  244.   fprintf(stderr, "neterrno=%d\n", neterrno);
  245.   if (neterrno && neterrno != 0xff)  return(-1);
  246.  
  247.   if (effrights) *effrights = repl.effrights;
  248.   return((int)repl.newhandle);
  249. }
  250.  
  251. int dealloc_dir_handle(int dhandle)
  252. {
  253.   struct {
  254.     uint16  len;
  255.     uint8   func;
  256.     uint8   dhandle;
  257.   } req;
  258.   struct {
  259.    uint16  len;
  260.   } repl;
  261.   req.len     = 2;
  262.   req.func    = 0x14;
  263.   req.dhandle = (uint8)dhandle;
  264.   repl.len    = 0;
  265.   neterrno    = Net_Call(0xE200, &req, &repl);
  266.   if (neterrno) return(-1);
  267.   else return(0);
  268. }
  269.  
  270. int set_dir_path(uint8 desthandle, uint8 handle, char *path)
  271. /* Set Directory Handle */
  272. {
  273.   struct {
  274.     uint16  len;
  275.     uint8   func;
  276.     uint8   desth;
  277.     uint8   sourceh;
  278.     uint8   pathlen;
  279.     uint8   path[256];
  280.   } req;
  281.   struct {
  282.     uint16  len;
  283.   } repl;
  284.   req.pathlen = (path) ? strlen(path) : 0;
  285.   if (req.pathlen) memcpy(req.path, path, (int)req.pathlen);
  286.   req.len     = 4+req.pathlen;
  287.   req.func    = 0;
  288.   req.sourceh = handle;
  289.   req.desth   = desthandle;
  290.   repl.len    = 0;
  291.   neterrno    = Net_Call(0xE200, &req, &repl);
  292.   return( (neterrno) ? -1 : 0);
  293. }
  294.  
  295. int get_dir_path(uint8 dhandle, char *path)
  296. {
  297.   struct {
  298.     uint16  len;
  299.     uint8   data[2];
  300.   } req;
  301.   struct {
  302.    uint16  len;
  303.    uint8   pathlen;
  304.    uint8   path[255];
  305.   } repl;
  306.   req.len     = 2;
  307.   req.data[0] = 0x1;
  308.   req.data[1] = dhandle;
  309.   repl.len    = 256;
  310.   neterrno    = Net_Call(0xE200, &req, &repl);
  311.   if (neterrno) return(-1);
  312.   else {
  313.     strmaxcpy(path, repl.path, (int)repl.pathlen);
  314.     return(0);
  315.   }
  316. }
  317.  
  318. int get_volume_name(uint8 nr, char *name)
  319. {
  320.   struct {
  321.     uint16  len;
  322.     uint8   func;
  323.     uint8   nr;
  324.   } req;
  325.   struct {
  326.    uint16  len;
  327.    uint8   namlen;
  328.    uint8   name[16];
  329.   } repl;
  330.   req.len     = 2;
  331.   req.func    = 0x6;
  332.   req.nr      = nr;
  333.   repl.len    = 17;
  334.   neterrno    = Net_Call(0xE200, &req, &repl);
  335.   if (neterrno) return(-1);
  336.   else {
  337.     strmaxcpy(name, repl.name, (int)repl.namlen);
  338.     return(0);
  339.   }
  340. }
  341.  
  342.  
  343. int save_dir_handle(uint8 dhandle, uint8 *savebuffer)
  344. {
  345.   struct {
  346.     uint16  len;
  347.     uint8   func;
  348.     uint8   dhandle;
  349.   } req;
  350.   struct {
  351.    uint16  len;
  352.    uint8   savebuffer[16];
  353.   } repl;
  354.   req.len     = 2;
  355.   req.func    = 0x17;
  356.   req.dhandle = dhandle;
  357.   repl.len    = 16;
  358.   neterrno    = Net_Call(0xE200, &req, &repl);
  359.   if (neterrno) return(-1);
  360.   else {
  361.     xmemmove(savebuffer, repl.savebuffer, 16);
  362.     return(0);
  363.   }
  364. }
  365.  
  366. int restore_dir_handle(uint8 *savebuffer, uint8 *dhandle, uint8 *effrights)
  367. {
  368.   struct {
  369.     uint16  len;
  370.     uint8   func;
  371.     uint8   savebuffer[16];
  372.   } req;
  373.   struct {
  374.    uint16   len;
  375.    uint8    dhandle;
  376.    uint8    effrights;
  377.   } repl;
  378.   req.len      = 17;
  379.   req.func     = 0x18;
  380.   repl.len     = 2;
  381.   xmemmove(req.savebuffer, savebuffer, 16);
  382.   neterrno     = Net_Call(0xE200, &req, &repl);
  383.   if (neterrno) return(-1);
  384.   else {
  385.     *dhandle   = repl.dhandle;
  386.     *effrights = repl.effrights;
  387.     return(0);
  388.   }
  389. }
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. int mapdrive(uint8 connection,   uint8 dhandle, char *path,
  401.              uint8 searchflag,   uint8 searchorder,
  402.              uint8 *driveletter, uint8 *newdhandle, uint8 *effrights)
  403.  
  404. /* Searchorder 0 normal Drive; 1..16 Searchdrives   */
  405. /* searchflag only if Searchdrive  :                */
  406. /* DRIVE_ADD, DRIVE_INSERT, DRIVE_DELETE            */
  407. {
  408.  
  409.  
  410.   return(-1);
  411. }
  412.  
  413.  
  414.  
  415.  
  416.  
  417.  
  418.  
  419.